package cn.ghx.xboot.order.price;

import cn.ghx.xboot.common.Result;
import cn.ghx.xboot.order.dto.OrderStatusDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/order/price")
public class OrderPriceController {


    public static final String POST = "";
    public static final String GET_LIST = "/list";
    public static final String DELETE = "/{id}";
    public static final String GET_BY_ID = "/{id}";
    public static final String PUT_STATUS = "/status";

    private final OrderPriceService service;

    public OrderPriceController(OrderPriceService service) {
        this.service = service;
    }

    @GetMapping(GET_BY_ID)
    public Result<OrderPrice> getById(@PathVariable String id){
        return Result.success(service.findById(id));
    }


    @DeleteMapping(DELETE)
    public Result<Boolean> delete(@PathVariable String id){
        return Result.success(service.deleteById(id));
    }

    @PostMapping(POST)
    public Result<Boolean> save(@RequestBody OrderPrice item){
        return Result.success(service.saveItem(item));
    }

    @GetMapping(GET_LIST)
    public Result<Page<OrderPrice>> getList(
            @RequestParam(required = false) String keyword ,
            @RequestParam(required = false) String openid ,
            @RequestParam(required = false) String phone ,
            @RequestParam(required = false) Integer status ,
            @RequestParam(required = false,defaultValue = "1") Integer page ,
            @RequestParam(required = false,defaultValue = "10") Integer size){
        return Result.success(service.query(keyword,
                openid ,
                phone ,
                status,
                page,size));
    }

    @PutMapping(PUT_STATUS)
    public Result<Boolean> putStatus(@RequestBody OrderStatusDto dto) {
        return Result.success(service.changeStatus(dto));
    }
}
